#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 300010;

int n, A, B, rt, dep[maxn], dfn[maxn], rnk[maxn], timer, sz[maxn], fa[maxn], son[maxn], top[maxn];
int a[maxn], f[maxn], g[maxn], h[maxn], csz[maxn], mxsz[maxn], vis[maxn], Rt, asz;
int cntg[maxn], cntgs[maxn], can[maxn], cans[maxn], all[maxn], alls[maxn], Mn[maxn];
vector<int> e[maxn], vec[maxn];
vector<pii> bel[maxn];

struct segtree {
  int t[maxn << 2];

  #define mid ((l + r) >> 1)

  void build(int c, int l, int r) {
    t[c] = 0;
    if (l == r) return;
    build(c << 1, l, mid), build(c << 1 | 1, mid + 1, r);
  }

  void upd(int c, int l, int r, int x, int y, int v) {
    if (l == x && r == y) return t[c] += v, void();
    if (y <= mid) upd(c << 1, l, mid, x, y, v);
    else if (x > mid) upd(c << 1 | 1, mid + 1, r, x, y, v);
    else upd(c << 1, l, mid, x, mid, v), upd(c << 1 | 1, mid + 1, r, mid + 1, y, v);
  }

  int qry(int c, int l, int r, int x) {
    if (l == r) return t[c];
    if (x <= mid) return t[c] + qry(c << 1, l, mid, x);
    else return t[c] + qry(c << 1 | 1, mid + 1, r, x);
  }

  #undef mid
} segG;

int kth(int x, int k) {
  while (x) {
    if (dep[x] - dep[top[x]] >= k) return rnk[dfn[x] - k];
    k -= dep[x] - dep[top[x]] + 1, x = fa[top[x]];
  }
  return 0;
}

void dfs(int u) {
  dep[u] = dep[fa[u]] + 1, sz[u] = 1;
  for (int v : e[u]) {
    if (v == fa[u]) continue;
    fa[v] = u, dfs(v), sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}

void dfs3(int u, int t) {
  top[u] = t, dfn[u] = ++timer, rnk[timer] = u;
  if (!son[u]) return;
  dfs3(son[u], t);
  for (int v : e[u]) {
    if (v == fa[u] || v == son[u]) continue;
    dfs3(v, v);
  }
}

void upd(int x) {
  for (auto e : bel[x]) chkmn(Mn[e.fi], e.se);
}

int qry(int x) {
  int res = n + 1;
  for (auto e : bel[x]) chkmn(res, Mn[e.fi] + e.se);
  return res;
}

void calcF(int x) {
  int has = can[x];
  if (!has) f[x] = !!all[x];
  else f[x] = (cntg[x] > 0 ? 0 : 1);
  if (f[x]) upd(x);
}

void calcG(int x) {
  if (x == rt) return;
  int o = fa[x], has = can[o] - cans[x];
  if (!has) g[x] = !!(all[o] - alls[x]);
  else g[x] = (cntg[o] - cntgs[x] ? 0 : 1);
  if (g[x]) segG.upd(1, 1, n, dfn[x], dfn[x] + sz[x] - 1, 1);
}

void calcH(int x) {
  int curg = segG.qry(1, 1, n, dfn[x]), up = kth(x, B);
  if (up) curg -= segG.qry(1, 1, n, dfn[up]);
  if (curg || qry(x) <= B) h[x] = 1;
  else h[x] = 0;
  int tmp = kth(x, A - 1);
  cans[tmp]++, cntgs[tmp] += !h[x];
  tmp = fa[tmp];
  can[tmp]++, cntg[tmp] += !h[x];
}

void makeall(int u) {
  for (int v : e[u]) {
    if (v == fa[u]) continue;
    makeall(v), all[u] += all[v], alls[u] += alls[v];
  }
}

bool check(int lim) {
  rep (i, 1, n) a[i] = (i <= lim), f[i] = g[i] = h[i] = 0;
  rep (i, 1, n) cntg[i] = cntgs[i] = can[i] = cans[i] = 0;
  rep (i, 1, n) all[i] = alls[i] = 0, Mn[i] = n + 1;
  rep (i, 1, n) if (a[i]) alls[i]++, alls[kth(i, B)]--, all[i]++, all[kth(i, B + 1)]--;
  makeall(rt), segG.build(1, 1, n);
  per (i, 2 * n, -2 * n) {
    if (i >= 1 && i <= n) {
      for (int x : vec[i]) calcF(x);
    }
    if (i - B + 1 >= 1 && i - B + 1 <= n) {
      for (int x : vec[i - B + 1]) calcG(x);
    }
    if (i >= 1 && i <= n) {
      for (int x : vec[i]) calcH(x);
    }
  }
  return f[rt];
}

void findrt(int u, int fa) {
  csz[u] = 1, mxsz[u] = 0;
  for (int v : e[u]) {
    if (vis[v] || v == fa) continue;
    findrt(v, u), csz[u] += csz[v];
    chkmx(mxsz[u], csz[v]);
  }
  chkmx(mxsz[u], asz - csz[u]);
  if (mxsz[u] <= asz / 2) Rt = u;
}

void dfs2(int u, int fa, int d, int r) {
  bel[u].emplace_back(r, d), csz[u] = 1;
  for (int v : e[u]) {
    if (vis[v] || v == fa) continue;
    dfs2(v, u, d + 1, r), csz[u] += csz[v];
  }
}

void solve(int u) {
  vis[u] = 1, bel[u].emplace_back(u, 0);
  for (int v : e[u]) {
    if (vis[v]) continue;
    dfs2(v, u, 1, u);
  }
  for (int v : e[u]) {
    if (vis[v]) continue;
    asz = csz[v], findrt(v, u), solve(Rt);
  }
}

int main() {
  freopen("nim.in", "r", stdin);
  freopen("nim.out", "w", stdout);
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n >> rt >> A >> B;
  rep (i, 1, n - 1) {
    int u, v;
    cin >> u >> v;
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }
  if (A <= B) return cout << "1\n", 0;
  dfs(rt), dfs3(rt, rt), asz = n, findrt(rt, 0), solve(Rt);
  rep (i, 1, n) vec[dep[i]].emplace_back(i);
  int l = 1, r = n, res = n + 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) res = mid, r = mid - 1;
    else l = mid + 1;
  }
  cout << res << '\n';
}